package com.cnswhy.cloud.server.comsumer.consumer;

import com.cnswhy.cloud.common.core.exception.BizException;
import com.cnswhy.cloud.common.core.utils.CnswhyUtil;
import com.cnswhy.cloud.common.core.utils.Kits;
import com.cnswhy.cloud.server.common.entity.enumeration.TransType;
import com.cnswhy.cloud.server.common.entity.mq.SpreadLogMsg;
import com.cnswhy.cloud.server.comsumer.event.SpreadMessageEvent;
import com.cnswhy.cloud.server.core.entity.Customer;
import com.cnswhy.cloud.server.core.entity.CustomerWallet;
import com.cnswhy.cloud.server.core.entity.SpreadLog;
import com.cnswhy.cloud.server.core.entity.WalletTransDtl;
import com.cnswhy.cloud.server.core.service.CustomerWalletService;
import com.cnswhy.cloud.server.core.service.SpreadLogService;
import com.cnswhy.cloud.server.core.service.WalletTransDtlService;
import com.cnswhy.cloud.server.core.service.customer.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SpreadMessageConsumer implements SpreadMessageEvent {
    @Autowired
    CustomerWalletService customerWalletService;
    @Autowired
    WalletTransDtlService walletTransDtlService;
    @Autowired
    CustomerService customerService;
    @Autowired
    SpreadLogService spreadLogService;

    @Override
    public void spread(SpreadLogMsg spreadLogMsg) {
        /*try{
            WalletTransDtl walletTransDtl = walletTransDtlService.getById(spreadLogMsg.getId());
            CustomerWallet customerWallet = customerWalletService.getById(walletTransDtl.getCustomerWalletId());
            Customer customer = customerService.getById(customerWallet.getCustomerId());
            SpreadLog spreadLog = new SpreadLog();
            spreadLog.setCreateDate(walletTransDtl.getCreateTime());
            spreadLog.setCustomerId(customer.getId());
            spreadLog.setMobile(customer.getLoginName());
            spreadLog.setShareCustomerId(customer.getPromoterId());
            spreadLog.setShareMobile(customer.getPromoterMobile());
            Long dedAmt = walletTransDtl.getDedBal();
            if(dedAmt < 0){
                dedAmt = - dedAmt;
            }
            spreadLog.setAmount(CnswhyUtil.getMoney(dedAmt));
            spreadLog.setOrderNum(walletTransDtl.getTransOrderId());
            //8分享红包9分享红包转余额10拼购券转余额11参与拼购12失败退回
            int type = 0;
            if(TransType.LOVE_BALANCE_CHARGE.eq(walletTransDtl.getTransType())){
                type = 1;
            }else if(TransType.CONTRIBUTION.eq(walletTransDtl.getTransType())){
                type = 2;
            }else if(TransType.SPELL_BALANCE_CHARGE.eq(walletTransDtl.getTransType())){
                type = 3;
            }else if(TransType.BACK_ORDER_CHARGE.eq(walletTransDtl.getTransType())){
                type = 4;
            }else if(TransType.LOVE_BALANCE_TRANSFER.eq(walletTransDtl.getTransType())){
                type  = 5;
            }else if(TransType.CONTRIBUTION_BALANCE_TRANSFER.eq(walletTransDtl.getTransType())){
                type = 6;
            }else if(TransType.SPELL_BALANCE_TRANSFER.eq(walletTransDtl.getTransType())){
                type = 7;
            }else if(TransType.SHARE_CHARGE.eq(walletTransDtl.getTransType())){
                type = 8;
            }else if(TransType.SHARE_TRANSFER.eq(walletTransDtl.getTransType())){
                type = 9;
            }else if(TransType.COUPON_TRANSFER.eq(walletTransDtl.getTransType())){
                type = 10;
            }else if(TransType.SPELL_ORDER.eq(walletTransDtl.getTransType())){
                type = 11;
            }else if(TransType.SPELL_ORDER_FAILURE.eq(walletTransDtl.getTransType())){
                type = 12;
            } else if (TransType.TEAM_BALANCE_TRANSFER.eq(walletTransDtl.getTransType())) {
                type = 13;
            } else if (TransType.TEAM_BALANCE_CHARGE.eq(walletTransDtl.getTransType())) {
                type = 14;
            }else if (TransType.SPLIT.eq(walletTransDtl.getTransType())) {
            }else if(TransType.SMALL_SPLIT.eq(walletTransDtl.getTransType())){
                type = 16;
            }else{
                type = -1;
            }
            spreadLog.setType(type);
            spreadLog.setBalance(CnswhyUtil.getMoney(walletTransDtl.getEndBal()));
            spreadLog.setSettDate(Kits.Date.getyyyyMMdd());
            spreadLogService.save(spreadLog);
        }catch (BizException e){
            log.info(e.getMessage());
        }*/
    }
}
